
import abspkg from './absaction.js'
import {LGXEnums} from '../../common/sysenum.js'
import LXCOM from '../../common/common.js'

class TextAction extends abspkg.AbsGraphAction {
    constructor(graph) {
        super(graph);
    }

    act2Mouse(mosEvnt, worldPos) {
        var graph = this.getRefGraph();
        if (graph == null) {
            return LGXEnums.LGXPlotState.ErrorState;
        }
        var state = LGXEnums.LGXPlotState.NoneState;
        let wid = 40;
        let hgt = 12;
        var position = graph.getPos();
        if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseDown) {
            if (graph.getStart() == 0) {
                
                position.left = worldPos.x - wid*0.5;
                position.top = worldPos.y + hgt*0.5;
                position.right = worldPos.x + wid*0.5;
                position.bottom = worldPos.y - hgt*0.5;

                graph.setStart(1);
                state = LGXEnums.LGXPlotState.AppendPtState;
            }
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseUp
            && graph.getFinish() == 0) {
            graph.setFinish(1);
            state = LGXEnums.LGXPlotState.OKState;
        }
        graph.calScope(1);
        return state;
    }
}

export default { TextAction }
